#include "Appointment.h"

Appointment::Appointment(){}

Appointment::Appointment(time start, time end, string subject){
	//if end is before start reject the app
	if(end < start)
		throw -1;
	this->start = start;
	this->end = end;
	this->subject = subject;
	this->duration = end - start;
}	

Appointment::Appointment(const Appointment &app):
start(app.start),end(app.end),subject(app.subject),duration(end-start){}

Appointment::~Appointment(){};

Appointment& Appointment::operator=(const Appointment& app){
	if(this != &app){
		start = app.start;
		end = app.end;
		subject = app.subject;
		duration = end - start;
	}
	return *this;
}

bool Appointment::operator ==(const Appointment& app) const{
	if(this == &app) return true;
	if(app.getStartTime() < this->getStartTime() && app.getEndTime() < this->getStartTime()){
		return false;
	}
	if(!(app.getStartTime() <= this->getStartTime() || app.getStartTime() <= this->getEndTime())){
		return false;
	}
	return true;
}

time Appointment::getStartTime() const{
	return this->start;
}

time Appointment::getEndTime() const{
	return this->end;
}

time Appointment::getDuration() const{
	return this->duration;
}

string Appointment::getSubject() const{
	return this->subject;
}


ostream& operator<<(ostream& os, const Appointment& app){
	// returns only the subjects because we want to print the times 
	// in a different row 
	return os << app.getSubject();	
	
}

